import { get, post, put } from './http'
import { uuid } from '@/utils/random'
import { useTtsaStore } from '@/store/ttsa'

const cfgUrl = '/h5/configuration/'
const processUrl = '/h5/process/'
const gateway = '/h5/question/'

const getCfg = () => {
  const uiEventId = uuid(32)
  const ttsa = useTtsaStore()
  ttsa.uiEventId = uiEventId
  return { headers: { 'UI-EVENT-ID': uiEventId } }
}

// 获取应用vhop信息
export const getVhopConfig = () => get(cfgUrl + 'digital_info/')

// 关闭vhop房间
export const closeVhopRoom = (data) => post(cfgUrl + 'close_room/', data)

// 授权
export const auth = (data) => post(cfgUrl + 'auth_sdk/', data)

// open房间
export const open = (data) => post('/explain/process/open/', data)

// start
export const start = (data) => post(processUrl + 'start/', data, getCfg())

// 继续上次未完节点
export const goon = (data) => post(processUrl + 'goon/', data, getCfg())

// 重新开始播放
export const reset = (data?) => post(processUrl + 'new/', data, getCfg())

// 进入下一节点
export const next = (data) => post(processUrl + 'next/', data, getCfg())

/**
 * @description 获取问题列表
 * @returns
 */
export const getQuestions = () => get(gateway)

/**
 * @description 提交问题
 * @returns
 */
export const question = (question_title: string, interrupt = true, chat_direct = false) => post(gateway, { question_title, interrupt, chat_direct }, getCfg())

/**
 * @description 问题回答完毕随机专场
 * @returns
 */
export const randomQuestion = () => put(`${gateway}random_question/`, null, getCfg())

// 设置分支节点信息
export const setBranch = (...arg) => post(processUrl + 'set_branch_selection/', ...arg)

// 获取目录
export const getCatalogue = (params) => get(processUrl + 'get_catalogue/', { params })

// 获取内容目录
export const getMenuCatalogue = () => get(processUrl + 'get_static_catalogue/')

// 暂停
export const pause = (data?) => post(processUrl + 'interrupt/', data)

// 调整清晰度
export const adj = (quality) => post(processUrl + 'ue4_config/', { quality })

// 暂停
export const explainToQa = (...arg) => post(processUrl + 'explain_to_qa/', ...arg)
